package com.tzinfo.tzt.activity.util;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tzinfo.tzt.R;
import com.tzinfo.tzt.activity.CarNewsDetailActivity;
import com.tzinfo.tzt.util.NewList;

import java.util.List;

/**
 * Created by bethinner on 2015/1/21.
 */
public class SJKXAdapter extends BaseAdapter {
    private List<NewList> data;
    private Context context;

public SJKXAdapter(Context context,List<NewList> data){
    this.context = context;
    this.data = data;
}
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_sjkx_adapter,parent,false);
            holder.sjkxadapter_tv = (TextView)convertView.findViewById(R.id.sjkxadapter_tv);
            convertView.setTag(holder);
        }
        else {
            holder =(ViewHolder)convertView.getTag();
        }
        holder.sjkxadapter_tv.setText(data.get(position).getTitle());
        holder.sjkxadapter_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CarNewsDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("Id", data.get(position).getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        return convertView;
    }
    class ViewHolder{
        TextView sjkxadapter_tv;
    }
}
